

function containVP(lineIndicesPairs, i0, i1) {
    let item = lineIndicesPairs.find(item => {
        return (item.i0 == i0 && item.i1 == i1) || (item.i0 == i1 && item.i1 == i0);
    });
    return item != null;
}

function calWireFrame(info) {
    // 获取所有的线段
    // 排除掉重复的
    let lineIndicesPairs = [];
    let indices = info.indices;
    let facelen = indices.length / 3;
    for (let i = 0; i < facelen; ++i) {
        let i0 = indices[3 * i];
        let i1 = indices[3 * i + 1];
        let i2 = indices[3 * i + 2];
        if (!containVP(lineIndicesPairs, i0, i1)) {
            lineIndicesPairs.push({i0: i0, i1: i1});
        }
        if (!containVP(lineIndicesPairs, i1, i2)) {
            lineIndicesPairs.push({i0: i1, i1: i2});
        }
        if (!containVP(lineIndicesPairs, i2, i0)) {
            lineIndicesPairs.push({i0: i2, i1: i0});
        }
    }

    // 计算 wireframe 需要的 indices
    info.lineIndicesArray = [];
    lineIndicesPairs.forEach(item => {
        info.lineIndicesArray.push(item.i0, item.i1);
    });
}

module.exports = {
    calWireFrame:calWireFrame,
};
